
package org.finegold.core.delivery.config;

import com.jd.open.api.sdk.DefaultJdClient;
import com.jd.open.api.sdk.JdClient;
import lombok.AllArgsConstructor;
import org.finegold.core.delivery.JdDeliveryTemplate;
import org.finegold.core.delivery.SfDeliveryTemplate;
import org.finegold.core.delivery.props.DeliveryProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;

/**
 * 物流配置类
 *
 * @author QinXueFeng
 */
@Configuration
@AllArgsConstructor
@EnableConfigurationProperties(DeliveryProperties.class)
public class DeliveryConfiguration {

	@Bean
	public SfDeliveryTemplate sfDeliveryTemplate(DeliveryProperties deliveryProperties) {
		return new SfDeliveryTemplate(deliveryProperties);
	}
	@Bean
	@DependsOn("jdClient")
	public JdDeliveryTemplate jdDeliveryTemplate(DeliveryProperties deliveryProperties, JdClient jdClient) {
		return new JdDeliveryTemplate(deliveryProperties,jdClient);
	}

	@Bean(name = "jdClient")
	public JdClient jdClient(DeliveryProperties deliveryProperties) {
		return new DefaultJdClient(deliveryProperties.getArgs().getStr("server-url"),deliveryProperties.getToken(),deliveryProperties.getAppKey(),deliveryProperties.getAppSecret());
	}

}
